package com.jxwifi.cloud.quickclean.adapter;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.bean.NavigationBean;
import com.jxwifi.cloud.quickclean.bean.ProductsBean;

import java.util.List;

public class FunctionAdapter extends BaseQuickAdapter<NavigationBean, BaseViewHolder> {

    private String TAG = this.getClass().getSimpleName();
    private DisplayMetrics dm;

    public FunctionAdapter(@LayoutRes int layoutResId, @Nullable List data,DisplayMetrics dm) {
        super(layoutResId, data);
        this.dm = dm;
    }

    @Override
    protected void convert(final BaseViewHolder helper, NavigationBean item) {

        /*ShadowLayout shadowLayout = (ShadowLayout) helper.getView(R.id.sl);
        shadowLayout.setIsShadowed(true);
        shadowLayout.setShadowAngle(45);//阴影角度
        shadowLayout.setShadowRadius(20);//阴影半径
        shadowLayout.setShadowDistance(30);//阴影距离
        shadowLayout.setShadowColor(Color.DKGRAY);//阴影颜色*/

        helper.setText(R.id.tv_function_title,item.getTitle());
        /*Glide.with(mContext).load(item.getImageUrl()).asBitmap()//签到整体 背景
                .into(new SimpleTarget<Bitmap>() {        //设置宽高
                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            //设置背景
                            //helper.setImageBitmap(R.id.img_function,resource);
                        }
                    }
                });*/
        //Glide.with(mContext).load(item.getLocalImage()).error(R.mipmap.icon_default_head).into((ImageView) helper.getView(R.id.img_function));
        //正确示范值：密度2.625 阴影283  图像244  阴影268 图像228  (int)(mRealSizeWidth*dm.densityDpi/dm.density/317.0642075325)
        ViewGroup.LayoutParams params2 = helper.getView(R.id.fra_function_img).getLayoutParams();
        /*params2.width = (int)(102.0952380952 * dm.density);//参考小程序
        params2.height = (int)(102.0952380952 * dm.density);//参考小程序*/
        //网管手机九宫格还有白边652.0754456801
        params2.width = (int)(dm.widthPixels*dm.densityDpi/dm.density/664.615085912);//参考小程序
        params2.height = (int)(dm.widthPixels*dm.densityDpi/dm.density/664.615085912);//参考小程序
        helper.getView(R.id.fra_function_img).setLayoutParams(params2);

        ViewGroup.LayoutParams params = helper.getView(R.id.img_function).getLayoutParams();
        /*params.width = (int)(86.8571428571 * dm.density);//参考小程序
        params.height = (int)(86.8571428571 * dm.density);//参考小程序*/

        params.width = (int)(dm.widthPixels*dm.densityDpi/dm.density/761.2334801762);//参考小程序
        params.height = (int)(dm.widthPixels*dm.densityDpi/dm.density/761.2334801762);//参考小程序
        helper.getView(R.id.img_function).setLayoutParams(params);
        //Log.i(TAG,"九宫格图片尺寸 params.width = "+params.width+" 阴影层尺寸 params2.width = "+params2.width);
        //Log.i(TAG, "convert ==> 九宫格图width = "+helper.getView(R.id.img_function).getLayoutParams().width/*+" 广告图height = "+params.height+" 屏幕width = "+width+" 屏幕height = "+height*/+" dpi = "+dm.densityDpi+" 密度 = "+dm.density+" 屏幕宽 ="+dm.widthPixels);

        Glide.with(mContext).load(item.getImageUrl()).error(R.mipmap.iconfont1).into((ImageView) helper.getView(R.id.img_function));

        helper.addOnClickListener(R.id.lin_main_function_items);
    }
}
